<template>
	<view class="container">
		<view class="bgimg">

		</view>
		<view class="zhongjian">
		<view class="warp">
			<u-form :model="model" :rules="rules" ref="uForm" :errorType="errorType">
				<u-form-item class="u-m-l-30 u-m-r-40" :label-width="200" :label-position="labelPosition" :border-bottom="true"
				 label="项目名称" prop="ppsx">
					<u-input type="select" :select-open="selectShowPpsx" v-model="model.ppsx" placeholder="请选择" placeholderStyle="color: #0D1D36;"
					 input-align="right" @click="selectShowPpsx = true"></u-input>
				</u-form-item>
				<u-form-item class="u-m-l-30 u-m-r-40" :label-width="200" :label-position="labelPosition" :border-bottom="true"
				 label="退款类型" prop="ppsx">
					<u-input type="select" :select-open="selectShowPpsx" v-model="model.ppsx" placeholder="请选择" placeholderStyle="color: #0D1D36;"
					 input-align="right" @click="selectShowPpsx = true"></u-input>
				</u-form-item>
				<u-form-item class="u-m-l-30 u-m-r-30" label-width="200" :label-position="labelPosition" label="退款金额" prop="gjz">
					<u-input :border="border" placeholder="请输入金额(万元)" v-model="model.gjz" type="text" input-align="right"></u-input>
				</u-form-item>
				<u-form-item class="zwpj u-m-l-30 u-m-r-30 " :label-position="labelPosition" prop="qtsm">
					<u-input type="textarea" :border="border" placeholder="请输入退款原因" v-model="model.qtsm" />
				</u-form-item>
				<u-gap :bg-color="bgColor" :height="height" :margin-top="marginTop" :margin-bottom="marginBottom"></u-gap>
				<view class="qtsm u-m-l-40 u-m-r-30 u-m-t-40">
					<image src="../../static/img/releasesm.png" style="width: 29rpx; height: 29rpx;" mode=""></image>
					<text class="hz">批复凭证</text>
				</view>
				<u-form-item class="u-m-l-30 u-m-r-30 " :label-position="labelPosition" prop="photo" label-width="150">
					<u-upload v-model="model.sczz" width="160"></u-upload>
				</u-form-item>
			</u-form>
		</view>
		<view class="u-m-t-20 u-p-30">

			<u-button class="button" @click="submit">提交</u-button>
			<!--弹出框-->
			<u-select mode="single-column" :list="wsList" v-model="selectShowWs" @confirm="selectConfirmWs"></u-select>
			<u-select mode="single-column" :list="wxyList" v-model="selectShowWxy" @confirm="selectConfirmWxy"></u-select>
			<u-select mode="single-column" :list="wyxList" v-model="selectShowWyx" @confirm="selectConfirmWyx"></u-select>
			<u-select mode="single-column" :list="selectList" v-model="selectShowQylx" @confirm="selectConfirmQylx"></u-select>
			<u-select mode="single-column" :list="selectList" v-model="selectShowQydy" @confirm="selectConfirmQydy"></u-select>
			<u-select mode="single-column" :list="selectList" v-model="selectShowLyxy" @confirm="selectConfirmLyxy"></u-select>
			<u-select mode="single-column" :list="selectList" v-model="selectShowPpsx" @confirm="selectConfirmPpsx"></u-select>
			<!--弹出框-->
		</view>
</view>
	</view>
</template>
<script>
	export default {
		data() {
			let that = this;
			return {
				height: 20,
				bgColor: this.$u.color.bgColor,
				marginTop: 30,
				marginBottom: 30,
				show: false,
				mode: 'range',
				result: "请选择日期",
				startText: '开始',
				endText: '结束',
				rangeColor: '#2979ff',
				rangeBgColor: 'rgba(41,121,255,0.13)',
				activeBgColor: '#2979ff',
				btnType: 'primary',
				reqBody: {},
				/**
				 * form验证
				 * */
				model: {
					ws: '',
					wxy: '',
					wyx: '',
					qymc: '',
					xmcc: '',
					xmdd: '',
					xmjd: '',
					zzyq: '',
					cjzt: '',
					xmbs: '',
					qtsm: '',
					xmmc: '',
					xhm: '',
				},
				startTime: '',
				endTime: '',
				selectList: [{
						value: '测试1',
						label: '测试1'
					},
					{
						value: '测试2',
						label: '测试2'
					},
					{
						value: '测试3',
						label: '测试3'
					}
				],
				wsList: [],
				wxyList: [],
				wyxList: [],
				rules: {
					// qymc: [
					// 	{
					// 		required: false,
					// 		message: '请输入企业名称',
					// 		trigger: 'blur'
					// 	}
					// ],
					ws: [{
						required: false,
						message: '请选择我是',
						trigger: 'change'
					}],
					wxy: [{
						required: false,
						message: '请选择我需要',
						trigger: 'change'
					}],
					wyx: [{
						required: false,
						message: '请选择我意向',
						trigger: 'change'
					}]
				},
				checkboxList: [{
						name: '企业',
						checked: false,
						disabled: false
					},
					{
						name: '团队',
						checked: false,
						disabled: false
					},
					{
						name: '无',
						checked: false,
						disabled: false
					},
				],
				checkboxListTwo: [

					{
						name: '是',
						checked: false,
						disabled: false
					},
					{
						name: '否',
						checked: false,
						disabled: false
					},
				],
				required: false,
				border: false,
				check: false,
				selectStatus: 'close',
				selectShowWs: false,
				selectShowWxy: false,
				selectShowWyx: false,
				selectShowQylx: false,
				selectShowQydy: false,
				selectShowLyxy: false,
				selectShowPpsx: false,
				radio: '',
				radio1: '',
				radioCheckWidth: 'auto',
				radioCheckWrap: false,
				labelPosition: 'left',
				codeTips: '',
				errorType: ['toast'],
				/**/

				/**
				 * 数字统计
				 * */
				startVal: 500,
				endVal: 500,
				separator: ',',
				decimals: 0,
				duration: 2000,
				autoplay: true,
				useEasing: true,
				current: 3,
				isStop: false,
				bold: false,
				fontSize: 24,
				color: '#fff',
				/**/
				keyIndex: 0,
				keywords: [{
					name: '企业',
					selected: true
				}, {
					name: '设计师',
					selected: false
				}, {
					name: '监理',
					selected: false
				}, {
					name: '大型企业',
					selected: false
				}, {
					name: '采购',
					selected: false
				}, {
					name: '监理',
					selected: false
				}]
			};
		},
		mounted() {},
		onShow() {
			this.wsDictionary();
			this.wxyDictionary();
			this.wyxDictionary();
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			qiehuan() {
				debugger
				var a = 3;
			},
			// checkbox选择发生变化
			checkboxGroupChange(e) {
				// debugger
				// this.model.cjzt = e;
				if (e === "企业") {
					this.model.cjzt = 0;
				} else if (e === "个人") {
					this.model.cjzt = 1;
				} else {
					this.model.cjzt = 2;
				}

			},
			// checkbox选择发生变化
			checkboxGroupChange1(e) {
				// this.model.xmbs = e;
				if (e === "是") {
					this.model.xhm = 1;
				} else {
					this.model.xhm = 0;
				}
			},
			async submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						console.log('验证通过');
						this.insertProject();
						this.matching();
					} else {
						console.log('验证失败');
					}
				});

			},
			//新增项目
			async insertProject() {
				try {
					this.reqBody['place'] = this.model['xmdd'];
					this.reqBody['name'] = this.model['xmmc'];
					this.reqBody['stage'] = this.model['xmjd'];
					this.reqBody['projectTime'] = this.result;
					this.reqBody['status'] = 1;
					let data = await this.$apis.saveProject(this.reqBody);
					console.log(JSON.stringify(data));
					// uni.setStorageSync("userInfo",data);
					if (data.code == 200) {
						uni.showToast({
							title: "添加招投标信息成功",
							icon: 'none'
						});
						// setTimeout(() => {
						// 	this.$mRouter.switchTab({
						// 		route:this.$mRoutesConfig.message
						// 	});
						// },500)

					} else {
						uni.showToast({
							title: result.msg,
							icon: 'none'
						});
						return;
					}
				} catch (e) {
					console.log(e);
					this.submitBtnDis = false;
				}
			},
			//招投标匹配
			async matching() {
				try {
					let reqBody = {};
					let bidding = {};
					let param = {};
					bidding['bidderId'] = this.$store.state.userInfo.id;
					bidding['area'] = this.model.xmdd;
					bidding['projectName'] = this.model.xmmc;
					bidding['level'] = this.model.xmcc;
					bidding['stage'] = this.model.xmjd;
					bidding['requires'] = this.model.zzyq;
					bidding['startTime'] = this.startTime;
					bidding['endTime'] = this.endTime;
					bidding['identityType'] = this.model.cjzt;
					bidding['isRebate'] = this.model.xhm;
					bidding['bestKey'] = this.model.gjz;
					bidding['blackKey'] = this.model.pbgjz;
					bidding['remarks'] = this.model.qtsm;
					param['iam'] = this.model.ws;
					param['imean'] = this.model.wyx;
					param['ineed'] = this.model.wxy;
					reqBody['bidding'] = bidding;
					reqBody['param'] = param;
					let data = await this.$apis.biddingMatching(reqBody);
					if (data.code == 200) {
						uni.showToast({
							title: "招投标匹配成功",
							icon: 'none'
						});
						setTimeout(() => {
							this.$mRouter.switchTab({
								route: this.$mRoutesConfig.message
							});
						}, 2000)

					} else {
						uni.showToast({
							title: result.msg,
							icon: 'none'
						});
						return;
					}
				} catch (e) {
					console.log(e);
					this.submitBtnDis = false;
				}
			},
			//查询匹配 我是  字典数据
			async wsDictionary() {
				let reqBody = {};
				reqBody['primary'] = "招投标";
				reqBody['secondary'] = "我是";
				let result = await this.$apis.findMatchingDictionary(reqBody);
				let list = result.data;
				for (let i = 0; i < list.length; i++) {
					let wsValue = {};
					wsValue['value'] = list[i].name;
					wsValue['label'] = list[i].name;
					this.wsList.push(wsValue)
				}
			},
			//查询匹配 我需要  字典数据
			async wxyDictionary() {
				let reqBody = {};
				reqBody['primary'] = "招投标";
				reqBody['secondary'] = "我需要";
				let result = await this.$apis.findMatchingDictionary(reqBody);
				let list = result.data;
				for (let i = 0; i < list.length; i++) {
					let wxyValue = {};
					wxyValue['value'] = list[i].name;
					wxyValue['label'] = list[i].name;
					this.wxyList.push(wxyValue)
				}
			},
			//查询匹配 我意向  字典数据
			async wyxDictionary() {
				let reqBody = {};
				reqBody['primary'] = "招投标";
				reqBody['secondary'] = "我意向";
				let result = await this.$apis.findMatchingDictionary(reqBody);
				let list = result.data;
				for (let i = 0; i < list.length; i++) {
					let wyxValue = {};
					wyxValue['value'] = list[i].name;
					wyxValue['label'] = list[i].name;
					this.wyxList.push(wyxValue)
				}
			},
			selectKey(e) {
				this.keywords[e].selected = !this.keywords[e].selected;
			},
			// 选择
			selectConfirmWs(e) {
				this.model.ws = '';
				e.map((val, index) => {
					this.model.ws += this.model.ws == '' ? val.label : '-' + val.label;
				});
			},
			selectConfirmWxy(e) {
				this.model.wxy = '';
				e.map((val, index) => {
					this.model.wxy += this.model.wxy == '' ? val.label : '-' + val.label;
				});
			},
			selectConfirmWyx(e) {
				this.model.wyx = '';
				e.map((val, index) => {
					this.model.wyx += this.model.wyx == '' ? val.label : '-' + val.label;
				});
			},
			selectConfirmQylx(e) {
				this.model.qylx = '';
				e.map((val, index) => {
					this.model.qylx += this.model.qylx == '' ? val.label : '-' + val.label;
				});
			},
			selectConfirmQydy(e) {
				this.model.qydy = '';
				e.map((val, index) => {
					this.model.qydy += this.model.qydy == '' ? val.label : '-' + val.label;
				});
			},
			selectConfirmPpsx(e) {
				this.model.ppsx = '';
				e.map((val, index) => {
					this.model.ppsx += this.model.ppsx == '' ? val.label : '-' + val.label;
				});
			},
			change(e) {
				if (this.mode == 'range') {
					this.result = e.startDate + " - " + e.endDate;
					this.startTime = e.startDate;
					this.endTime = e.endDate;
				} else {
					this.result = e.result;
				}
			},
			dianji() {
				this.show = true;
			}
		}
	};
</script>
<style scoped lang="scss">
	page {
		background: #f5f5f9;
	}
      .container{
		  position: relative;
	  }

	.bgimg {
		width: 100%;
		height: 365upx;
		background: linear-gradient(0deg, #AC62FF, #DF62FF);
	}

	.warp {
		background: #fff;

	}
	.zhongjian{
		// border: 1px solid;
		position: absolute;
		top: 10%;
		width: 90%;
		left: 5%;
		margin: 0 auto;
		
	}

	.count {
		.count-to {
			font-size: 24rpx;
		}

		text {
			padding: 2rpx 12rpx;
			background: #ff9e21;
			color: #ffffff;
			font-size: 24rpx;
		}
	}



	.button {
		width: 602rpx;
		margin: 145rpx auto 65rpx auto;
		background: #ab61ff;
		border-radius: 40rpx;
		border: 0;
		color: #fff;

		&.u-hairline-border:after {
			border: 0;
		}
	}

	.wdztc {
		width: 190rpx;
		height: 56rpx;
		background: rgba(171, 97, 255, 0.15);
		border: 2rpx dashed #AB61FF;
		border-radius: 6rpx;
		color: #AB61FF;
		font-size: 28rpx;
		text-align: center;
		line-height: 56rpx;
		margin-top: 40rpx;
		margin-left: 280rpx;
	}

	.qtsm {
		display: flex;
		align-items: center;

		.hz {
			color: #0D1D36;
			font-size: 30rpx;
			margin-left: 15rpx;
		}
	}

	.zwpj {
		width:90%;
		height: 260rpx;
		background-color: #F5F5F9;
		margin-top: 40rpx;
		font-size: 30rpx;
		color: #F5F5F9;
		border-radius: 10rpx;
		line-height: 44rpx;
	}
</style>
